from PyQt5.QtWidgets import QCheckBox

from .._config import UI_RES_PATH


class QSwitch(QCheckBox):
    def __init__(self, parent=None, indicatorSize=(60, 60), checked=False):
        super(QSwitch, self).__init__(parent)
        self.setChecked(checked)
        self.setIndicatorSize(indicatorSize)

    def setIndicatorSize(self, size: tuple):
        """
        Args:
            size: (w, h)
        """
        self.setStyleSheet('''
            QCheckBox::indicator {
                width: %fpx;
                height: %fpx
            }
            QCheckBox::indicator:unchecked {
                image: url(%s);
            }
            QCheckBox::indicator:checked {
                image: url(%s);
            }
        ''' % (*size, UI_RES_PATH / 'switch_off.png', UI_RES_PATH / 'switch_on.png'))


if __name__ == '__main__':
    import sys
    from PyQt5.Qt import QApplication

    app = QApplication(sys.argv)
    win = QSwitch()
    win.show()
    sys.exit(app.exec_())
